package com.hsource.doctorcenter.service.dict.impl;

import cn.hutool.core.convert.Convert;
import com.hsource.doctorcenter.conf.dataSource.aspect.SnowflakeIdWorker;
import com.hsource.doctorcenter.domain.dict.DictData;
import com.hsource.doctorcenter.mapper.DictDataMapper;
import com.hsource.doctorcenter.service.dict.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

/**
 * 字典数据Service业务层处理
 *
 * @author yangyang
 * @date 2020-09-24
 */
@Service
public class DictDataServiceImpl implements IDictDataService {
    @Autowired
    private DictDataMapper dictDataMapper;

    /**
     * 查询字典数据
     *
     * @param id 字典数据ID
     * @return 字典数据
     */
    @Override
    public DictData selectDictDataById(String id) {
        return dictDataMapper.selectDictDataById(id);
    }

    /**
     * 查询字典数据列表
     *
     * @param dictData 字典数据
     * @return 字典数据
     */
    @Override
    public List<DictData> selectDictDataList(DictData dictData) {
        return dictDataMapper.selectDictDataList(dictData);
    }

    /**
     * 根据字典类型查询字典数据
     *
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    @Override
    public List<DictData> selectDictDataByType(String dictType){
        return dictDataMapper.selectDictDataByType(dictType);
    }

    /**
     * 新增字典数据
     *
     * @param dictData 字典数据
     * @return 结果
     */
    @Override
    public int insertDictData(DictData dictData) {
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1);
        long l = idWorker.nextId();
        dictData.setId(String.valueOf(l));
        dictData.setCreateTime(Calendar.getInstance().getTime());
        return dictDataMapper.insertDictData(dictData);
    }

    /**
     * 修改字典数据
     *
     * @param dictData 字典数据
     * @return 结果
     */
    @Override
    public int updateDictData(DictData dictData) {
        return dictDataMapper.updateDictData(dictData);
    }

    /**
     * 删除字典数据对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteDictDataByIds(String ids) {
        return dictDataMapper.deleteDictDataByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除字典数据信息
     *
     * @param id 字典数据ID
     * @return 结果
     */
    @Override
    public int deleteDictDataById(String id) {
        return dictDataMapper.deleteDictDataById(id);
    }
}
